package it.pir.es02ChatTCP;

import java.io.*;
import java.net.*;
import java.util.HashMap;
import java.util.Map;

public abstract class Server {

	private static final int PORT = 7777;

	protected Map<String,OutputStream> clients;
	protected ServerSocket serverSocket;
	protected ChatWindow chat;

	public Server(int port) throws IOException {
		clients = new HashMap<String,OutputStream>();
		serverSocket = new ServerSocket(port);
		chat = new ChatWindow();
        chat.setVisible(true);
        chat.setSize(800, 600);
	}
	
	public void addClient(String nickname, OutputStream clientObjectOutputStream) {
		clients.put(nickname, clientObjectOutputStream);
	}
	
	public void removeClient(String nickname) {
		clients.remove(nickname);
	}
	
	public abstract void broadcastSend(String nickname, Message message) throws IOException;
	
	public abstract void start();

	public static void main(String[] args) throws IOException {
		// TODO: qui si cambiano le implementazioni
		Server server = new ServerObj(PORT);
		//Server server = new ServerBin(PORT);
		//Server server = new ServerTxt(PORT);
		server.start();
	}

}
